import time

import allure
from selenium.webdriver.common.by import By

from cloud_po.pages.base_page import BasePage
from cloud_po.utils.log_utils import logger


class ProductAddPage(BasePage):
    __INPUT_PNAME = (By.XPATH, "//*[text()='商品名称']/..//input")
    __INPUT_CWAREHOUSE = (By.XPATH, "//*[text()='所属仓库(供应商)']/..//input")
    __INPUT_CWAREHOUSE_CHOOSE = (By.XPATH, "//*[text()='测试仓库']")
    __SAVE_BTN = (By.XPATH, "//span[text()='提交']")
    __INPUT_SPEC = (By.CSS_SELECTOR, ".edit-input.el-input.el-input--small>.el-input__inner")

    def add_product(self,product_name):
        logger.info("添加商品")
        with allure.step("填写商品表单"):
            self.do_find(self.__INPUT_PNAME).click()
            self.do_send_keys(product_name,self.__INPUT_PNAME)

            self.do_find(self.__INPUT_CWAREHOUSE).click()
            self.do_find(self.__INPUT_CWAREHOUSE_CHOOSE).click()

            self.do_send_keys("7788",self.__INPUT_SPEC)
        with allure.step("点击提交"):
            self.do_find(self.__SAVE_BTN).click()
        from cloud_po.pages.product_page import ProductPage
        return ProductPage(self.driver)